<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

    </style>
</head>

<body>
    <div>
        <input>
    </div>
    <div class="box">
        <button>111</button>
        <button>222</button>
        <button>333</button>
        <button>444</button>
    </div>
    <script>
        let input = document.querySelector('input');
        let button = document.querySelector('.box').querySelectorAll('button');
        for(let i = 0; i<button.length;i++){
            button[i].onclick = function () {
                for(let i = 0; i<button.length;i++){
                    button[i].style.background = 'rgb(239, 239, 239)'
                }
                this.style.background = 'red'
            }
        }
        let flag = 1
        document.addEventListener('keydown', function (e) {
            console.log(e.keyCode)
            if (flag == 1) {
                if (e.keyCode == '13') {
                    input.style.background = 'tan';
                    input.value = '这是回车事件';
                    flag = 0;
                }
            } else {
                input.style.background = '';
                input.value = '';
                flag = 1;
            }

        })
    </script>
</body>

</html>